package com.zzz.offer.rotating;

public class Rotating {
    public static void main(String[] args) {
        System.out.println(new Rotating().minNumberInRotateArray(new int[]{}));

    }

    public int minNumberInRotateArray(int[] array) {
        if (array.length == 0) {
            return -1;
        }
        if (array.length == 1) {
            return array[0];
        }


        int low = 0, high = array.length - 1;
        int mid = (low + high) / 2;

        if (array[high] > array[low]) {
            return array[low];
        }

        while (high - low > 1) {

            if (array[mid] < array[high])
                high = mid;
            else if (array[mid] > array[high])
                low = mid;
            else {
                high--;
            }

            mid = (low + high) / 2;

            // 为什么要写着行代码，为什么不把high -- 放上去
//            if (array[low] == array[high] || array[mid] == array[high]) {
//                high--;
//                mid = (low + high) / 2;
//            }

        }
        return array[high];
    }
}
